//
//  TableViewCellMiddleCommon.m
//  UI_homework_22_QQ音乐界面和阿里星球界面
//
//  Created by li cheng on 16/8/13.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "TableViewCellMiddleCommon.h"
#import "CollectionViewCellMiddleCommon.h"
@interface TableViewCellMiddleCommon()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UILabel *titlteLabel;
@property (nonatomic, strong) UIButton *moreButton;
@property (nonatomic, strong) UICollectionView *myCollectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) UILabel *songName;
@property (nonatomic, strong) UILabel *songer;
@end
@implementation TableViewCellMiddleCommon
#pragma mark - 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _layout = [[UICollectionViewFlowLayout alloc] init];
        _myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_layout];
        _myCollectionView.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:_myCollectionView];
        _myCollectionView.delegate = self;
        _myCollectionView.dataSource = self;
        [_myCollectionView registerClass:[CollectionViewCellMiddleCommon class] forCellWithReuseIdentifier:@"CollectionViewCellMiddleCommon"];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    // contentView 的宽高
    CGFloat widthOfContentView = self.contentView.bounds.size.width;
    CGFloat heightOfContentView = self.contentView.bounds.size.height;
    // CollectionView 的宽高
    CGFloat widthOfCollectionView = widthOfContentView;
    CGFloat heightOfCollectionView = heightOfContentView;
    _myCollectionView.frame = CGRectMake(0, 0, widthOfCollectionView, heightOfCollectionView);
    // layout 的设置
    CGFloat edge = 5;
    CGFloat widthOfItem = (widthOfContentView - 4 * edge) / 3;
    CGFloat heightOfItem = heightOfContentView  - 2 * edge;
    _layout.itemSize = CGSizeMake(widthOfItem, heightOfItem);
    _layout.minimumLineSpacing = 0;
    _layout.minimumInteritemSpacing = edge;
    _layout.sectionInset = UIEdgeInsetsMake(edge, edge, edge, edge);
    
}
#pragma mark - item 的数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 3;
}
#pragma mark - cell 赋值
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    CollectionViewCellMiddleCommon *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCellMiddleCommon" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor grayColor];
    return cell;
}
#pragma mark - 其他
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
